/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ipti.br.tag.bean.questionnaire;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Named;
import javax.enterprise.context.Dependent;
import javax.faces.view.ViewScoped;
import javax.inject.Inject;

import org.ipti.br.tag.bo.HbBO;
import org.ipti.br.tag.bo.HumanBO;
import org.ipti.br.tag.bo.UnityBO;
import org.ipti.br.tag.entity.Human;
import org.ipti.br.tag.entity.Unity;
import org.ipti.br.tag.bean.AppBaseBean;
import org.ipti.br.tag.bean.SessionBean;

/**
 *
 * @author ipti008
 */
@Named @ViewScoped
public class GenerateTermBean extends AppBaseBean implements Serializable{
    
    private List<Human> selectedHumans, activateds;
    @Inject private HbBO hbBO;
    @Inject private HumanBO humanBO;
    @Inject private UnityBO unityBO;
    @Inject private SessionBean sessionBean;
    
    private Unity unity;
    
    private Integer year = getActualYear();
    
    public void loadHumanList(){
        activateds = humanBO.getHumans(unity);
        selectedHumans = new ArrayList<>(activateds);
    }
    
    public void generate() {
        boolean sucess = hbBO.generateConsentTerm(selectedHumans, unity);
        if (sucess) {
            addInfoMessage(":createConsentForm:message", "Sucesso!", "Os relatórios gerados estão lindos, né? :D");
        } else {
            addErrorMessage(":createConsentForm:message", "Ocorreu algum provlema ao gerar os relatórios", ":(");
        }
    }
       
    public List<Unity> getUnityList() {
        List<Unity> list = unityBO.getClassLessonList(sessionBean.getLoggedActor().getUnity(),year);
        return list;
    }

    public List<Human> getSelectedHumans() {
        return selectedHumans;
    }

    public void setSelectedHumans(List<Human> selectedHumans) {
        this.selectedHumans = selectedHumans;
    }

    public Integer getYear() {
        return year;
    }

    public void setYear(Integer year) {
        this.year = year;
    }

    public Unity getUnity() {
        return unity;
    }

    public void setUnity(Unity unity) {
        this.unity = unity;
    }

    public List<Human> getActivateds() {
        return activateds;
    }

    public void setActivateds(List<Human> activateds) {
        this.activateds = activateds;
    }
}
